package thread;

/**
 * 静态方法上入如果使用了synchronized,那么该方法一定具有同步效果
 */
public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1 = new Foo();
        Foo f2 = new Foo();
        Thread t1 = new Thread(){
            public void run(){
                f1.dosome();
            }
        };
        Thread t2 = new Thread(){
            public void run(){
                f2.dosome();
            }
        };
        t1.start();;
        t2.start();
    }
}
class Foo{
    public synchronized  void dosome(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行dosome方法");
            Thread.sleep(5000);
            System.out.println(t.getName()+"执行结束");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
